package com.zm.dao;

import com.zm.domain.Account;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface IAccountDao {
    //查询所有数据的方法
    //一对一的查询方式
    @Select("select * from account")
    @Results(id = "accountMapToOne",
            value = {
                    @Result(id = true,column = "id",property = "userId"),
                    @Result(column = "uid",property = "userUid"),
                    @Result(column = "money",property = "userMoney"),
                    //one属性代表当前对一的意思，里面是@One的对象，存放一对一查询需要用到的查询语句的namespace
                    //fetchType设置了加载方式为立即加载，此处为一对一所以要用立即加载，即设置为EAGER
                    @Result(property = "user",column = "uid",one = @One(select = "com.zm.dao.IUserDao.findById",fetchType = FetchType.EAGER))
            }
    )
    public List<Account> selectAll();

    @Select("select * from account where id=#{id}")
    @Results(id = "accountMap",
            value = {
                    @Result(id = true, column = "id", property = "userId"),
                    @Result(column = "uid", property = "userUid"),
                    @Result(column = "money", property = "userMoney"),
            })
    public List<Account> findById(Integer id);


    @Select("select * from account where uid=#{id}")
    @ResultMap(value = {"accountMap"})
    public List<Account> findByUid(Integer id);

}
